package com.dm.cloud.auth.controller.defalut;

import com.dm.cloud.auth.common.mode.AppUserStatistics;
import com.dm.cloud.auth.common.mode.AuthAppClientDetail;
import com.dm.cloud.core.mode.ResultModel;
import com.dm.cloud.oauthlib.service.anon.HasLogin;
import com.dm.cloud.tkmybatis.service.BaseEntityService;
import com.dm.cloud.tkmybatis.service.EntityBaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.dm.cloud.auth.common.po.AuthApp;
import com.dm.cloud.auth.common.dto.AuthAppDTO;
import com.dm.cloud.auth.common.request.AuthAppSearchRequest;
import com.dm.cloud.auth.service.AuthAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
   * @author hcx
   * @type AuthAppController.java
   * @desc 应用表 AuthApp controller
   */
@RestController
@RequestMapping("/apis/v1/authApp")
@Tag(name =  "应用表  AuthAppcontroller")
@HasLogin
public class AuthAppController extends EntityBaseController<AuthAppSearchRequest, AuthApp, AuthAppDTO> {

    @Autowired
    private AuthAppService authAppService;
    @Override
    public AuthApp getEntity() {
        return new AuthApp();
    }

    @Override
    public AuthAppDTO getDTO() {
        return new AuthAppDTO();
    }
    @Override
    public BaseEntityService<AuthAppSearchRequest, AuthApp> getService() {
        return authAppService;
    }

    @GetMapping("clientDetail")
    @Operation(summary = "获取应用客户端认证信息")
    public ResultModel<AuthAppClientDetail> clientDetail(
            @Parameter(in = ParameterIn.QUERY,name = "appId",description = "应用ID",required = true) String appId
    ){
        AuthAppClientDetail detail=authAppService.appClientDetail(appId);
        return ResultModel.success(detail);
    }

    @GetMapping("findByAppCode")
    @Operation(summary = "根据code获取应用信息")
    public ResultModel<AuthApp> findByAppCode(
            @Parameter(in = ParameterIn.QUERY,name = "appCode",description = "appCode",required = true) String appCode
    ){
        AuthApp detail=authAppService.findByAppCode(appCode);
        return ResultModel.success(detail);
    }

    @GetMapping("appCodeName")
    @Operation(summary = "获取应用code和名称的映射关系Map")
    public ResultModel<Map<String,String>> appCodeName(){
        Map<String,String> detail=authAppService.appCodeName();
        return ResultModel.success(detail);
    }

    @GetMapping("appUserStatistics")
    @Operation(summary = "应用关联的用户数量统计")
    public ResultModel<AppUserStatistics> appUserStatistics(@Parameter(in = ParameterIn.QUERY,name = "appCode",description = "appCode",required = true) String appCode){
        AppUserStatistics appUserModel=authAppService.appUserStatistics(appCode);
        return ResultModel.success(appUserModel);
    }

}
